package com.zhf.JDBC03;

import com.zhf.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/9/23 22:08
 */
public class TestPS {

    public static void main(String[] args) throws SQLException {

        Connection connection = JDBCUtils.getConnection();

        Statement statement = connection.createStatement();

        statement.executeUpdate("insert into jdbc_user values(null,'张三','123456','2000/11/12')");
        statement.executeUpdate("insert into jdbc_user values(null,'李四','123456','2001/12/22')");

        //预处理对象
        PreparedStatement preparedStatement = connection.prepareStatement("insert into jdbc_user values(?,?,?,?)");

        //插入数据
        preparedStatement.setObject(1,null);
        preparedStatement.setString(2,"田恰翔");
        preparedStatement.setString(3,"654321");
        preparedStatement.setString(4,"1999/11/11");

        //执行插入操作
        preparedStatement.executeUpdate();

        //释放资源
        JDBCUtils.close(connection,statement);


    }
}
